package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.LiveParentInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrater on 2015/12/7.
 */
public class LiveDynamicTask extends CouponHttpBaseTask {
    private String mVid;
    private String mNowTime;
    private String mSize;

    public LiveDynamicTask(String vid,String nowTime,String size) {
        mVid = vid;
        mNowTime = nowTime;
        mSize = size;
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest();
            JSONObject json = new JSONObject();
            json.put("vid", mVid);
            json.put("nowTime",mNowTime);
            json.put("size",mSize);
            request.setData(json.toString());
            request.setApiNo(ApiNo.LIVEDYNAMIC);
            addRequest(request);
        }
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject respJson = response.getBody();
        LiveParentInfo info = null;
        if (respJson != null) {
            info = JSON.parseObject(respJson.getString("liveDetail"), LiveParentInfo.class);
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS, info);
    }
}
